import time
from datetime import datetime

import pandas
import pandas as pd
import geopandas as geo
import matplotlib.pyplot as plt
from math import cos, sin, atan2, sqrt, pi, radians, degrees

# pandas show all rows
pd.set_option('display.max_rows', None)
# pandas show all col
pd.set_option('display.max_columns', 20)
# dataframe打印不换行
pd.set_option('display.width', 5000)

#####################################################
# order is sorted by open_time and arr_time
#####################################################

# ---------------------function-----------------------

# draw board
fig = plt.figure(1, (16, 9), dpi=120)
ax = plt.subplot(111)
plt.sca(ax)

start = time.time()

# 1.read order file
order = pd.read_csv('E:\DataSet\zipcar_now\order.csv')

print(order.shape)
print(order.head())
# plt.scatter(order['up_lon'], order['up_lat'], marker='o', alpha=0.5, s=2, c='green')
# plt.scatter(order['off_lon'], order['off_lat'], marker='o', alpha=0.5, s=2, c='red')

order.drop(['off_time'], axis=1, inplace=True)
print(order.head())
##order.to_csv('E:/DataSet/zipcar_now/nextData/order_otime.csv',index=False)
# order_o = geo.GeoDataFrame(order,geometry=geo.points_from_xy(order.up_lon, order.up_lat))
# print(order_o.head())

# read map
map = geo.read_file('../data/map/NewYork.shp')
map.plot(ax=ax, edgecolor=(0, 0, 0, 1), facecolor=(0, 0, 0, 0), linewidths=0.5)

# read grid geodataframe
grid = geo.read_file('E:\DataSet\zipcar_now\grid.shp')
# grid.drop(['left','top','right','bottom'],axis=1,inplace=True)
## grid.to_csv('E:/DataSet/zipcar_now/nextData/grid.csv',index=False)
## grid.to_file('E:/DataSet/zipcar_now/nextData/grid.shp',index=False)
print(grid.shape)
print(grid.head())
grid.plot(ax=ax, edgecolor=(0, 0, 0, 1), facecolor=(0, 0, 0, 0), linewidths=0.5)


# read zip site
site = pd.read_csv('E:/DataSet/zipcar_now/site_merge_center.csv')
## site.to_csv('E:/DataSet/zipcar_now/nextData/zip.csv',index=False)
print(site.shape)
print(site.head())

# merge site and grid
station = pd.merge(site,grid)
print(type(station))
print(station.head())
# station.plot(ax=ax, edgecolor=(0, 0, 0, 1), facecolor=(0, 0, 0, 0), linewidths=0.5)
# station['id'] = station.index
station.to_csv('E:/DataSet/zipcar_now/nextData/station.csv',index=False)

# count program runtime
print('run time:', time.time() - start, 's')

# show draw board
plt.show()
